<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-collapse" lay-filter="driver">
        <div class="layui-colla-item">
            <h2 class="layui-colla-title" data-v="driver">个人基本信息</h2>
            <div class="layui-colla-content layui-show">
                <table class="layui-table">
                    <volist name="fields" id="field" key="k">
                        <tr>
                            <td>{$field}</td>
                            <if condition="in_array($key,$img)">


                                    <php>$thumb = $key.'_thumb';</php>
                                    <td class="layer-photos-demo">
                                        <img  id="image_{$k}" layer-src="{$info[$key]}" alt="{$info['driver_name']}{$field}" src="{$info[$thumb]?:$info[$key]}">
                                        <button type="button" class="layui-btn uploads"  id="upload-{$k}-{$key}" >上传图片</button>
                                    </td>

                                <elseif condition="$key eq auth_type"/>
                                <td>{$auth_type[$info[$key]]}</td>
                                <elseif condition="$key eq license_time"/>
<!--                                <td>{$info['license_time']}</td>-->
                                <td><input type="text" name="license_time" id="license_time" value="{$info['license_time']}" lay-verify="required" placeholder="活动开始时间"
                                       class="layui-input" style="width: 150px;float: left;margin-right: 10px;">
                                    <button class="layui-btn layui-btn-danger layui-btn-sm" onclick="admin_update(this,'xm_driver_info','{$key}','driver_id',{$info['driver_id']})">修 改</button>
                                </td>
                                <elseif condition="$key eq valid_time"/>
                                <td><input type="text" name="valid_time" value="{$info['valid_time']}" id="valid_time" lay-verify="required" placeholder="活动开始时间"
                                           class="layui-input" style="width: 150px;float: left;margin-right: 10px;">
                                    <button class="layui-btn layui-btn-danger layui-btn-sm" onclick="admin_update(this,'xm_driver_info','{$key}','driver_id',{$info['driver_id']})">修 改</button>
                                </td>
                                <elseif condition="$key eq work_province"/>
                                <td>{$info['province']}{$info['city']}{$info['county']}</td>
                                <elseif condition="$key eq driver_avatar"/>
                                <empty name="info[$key]">
                                    <td><span>{$info['driver_name']}{$field}</span>{$tip}</td>
                                    <else/>
                                    <php>$thumb = $key.'_thumb';</php>
                                    <td class="layer-photos-demo">
                                        <img layer-src="{$info[$key]}" alt="{$info['driver_name']}{$field}" src="{$info[$thumb]?:$info[$key]}">{$tip}
                                    </td>
                                </empty>
                                <else/>
                                <td>
                                    <if condition="in_array($key,$Think.config.ADMIN_EDIT.xm_driver)">
                                   <input type="text" value="{$info[$key]}" class="layui-input abc" style="width:150px;display: inline;margin-right: 15px"><button class="layui-btn layui-btn-danger layui-btn-sm" onclick="admin_update(this,'xm_driver_base','{$key}','driver_id',{$info['driver_id']})">修 改</button>
                                    <else />
                                     {$info[$key]}
                                    </if>

                                </td>
                            </if>
                        </tr>
                    </volist>
                </table>
            </div>
        </div>
        <!--<div class="layui-colla-item">
            <h2 class="layui-colla-title"  data-v="car" data-value="{$info['driver_id']}" data-act="no">车辆基本信息</h2>
            <div class="layui-colla-content">

            </div>
        </div>
        <div class="layui-colla-item">
            <h2 class="layui-colla-title"  data-v="auth" data-value="{$info['driver_id']}" data-act="no">司机审核信息</h2>
            <div class="layui-colla-content">

            </div>
        </div>-->
    </div>

    <script>
        layui.use(['layer','upload','element','laydate'], function(){
            var layer = layui.layer;
            var element = layui.element;
            var upload = layui.upload;
            form = layui.form;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#license_time'
                , min: '<?php echo date("Y-m-d",strtotime("+1 day"));?>'
            });
            laydate.render({
                elem: '#valid_time'
                , min: '<?php echo date("Y-m-d",strtotime("+1 day"));?>'
            });
            layer.photos({
                photos: '.layer-photos-demo'
                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                ,tab: function(pic, layero){
                    var str = "<div style='text-align: center'>"+pic.alt+"</div>";
                    layero.prepend(str);
                }
            });
            var $ = layui.jquery;
            element.on('collapse(driver)', function(data){
                var title = data.title;
                switch (title.data('v')){
                    case 'car':
                        if(title.data('act')=='no'){
                            title.data('act','yes');
                            $.post('/admin/driver/carInfoEdit',{driver_id:title.data('value')},function (res) {
                                switch (res['status']){
                                    case 1:
                                        data.content.html(res['html']);
                                        break;
                                    default:
                                        layer.alert(res['msg'],{icon: 5});
                                        break;
                                }
                            },'json')
                        }
                        break;
                    case 'auth':
                        if(title.data('act')=='no'){
                            title.data('act','yes');
                            $.post('/admin/driver/authInfo',{driver_id:title.data('value')},function (res) {
                                switch (res['status']){
                                    case 1:
                                        data.content.html(res['html']);
                                        break;
                                    default:
                                        layer.alert(res['msg'],{icon: 5});
                                        break;
                                }
                            },'json')
                        }
                    default:
                        break;
                }
            });
            var k;
            var table_field;
            var table_id = {$info['driver_id']};
            upload.render({
                elem: '.uploads'//这个就等同于点击
                ,url: '/admin/Upload/upload'
                ,before: function(obj){
                    var id_str='';
                    console.log(this.item.context.id)
                    id_str=this.item.context.id
                    var arr=id_str.split("-");
                    k = arr[1];
                    console.log(k);
                    table_field =  arr[2];
                    console.log(table_field)
                  //预读本地文件示例，不支持ie8
                }
                ,done:  function(res){ //上传后的回调
                    console.log(res)
                    console.log(k)
                  if(res.status == 1){
                    $("#image_"+k).attr('src',res.data.file); //点击后的大图
                    $("#image_"+k).attr('layer-src',res.data.file_thumb); //小图
                    $.post('/admin/upload/image_edit',{'table_name':'xm_driver_info','table_field':table_field,'table_id':'driver_id','id_value':table_id,'field_value':res.data.file,'thumb':res.data.file_thumb},function(data){
                        console.log(data)
                        if(data.code == 1){
                            layer.msg(data.msg,{icon: 1});
                        }else{
                            layer.msg(data.msg,{icon: 2});
                        }
                    },'json')
                  }else{
                    layer.msg(res.msg);
                  }

                }
                ,error: function(e){
                    console.log(e)
                  //layer.msg('上传失败');

                }
                });
        });
        //更改后台字段
        function admin_update(obj,table_name,table_field,table_id,id_value,encrypt){
            var new_obj = $(obj);
            layer.confirm('确定修改', function(index){
                var field_value = new_obj.prev('input').val();
                $.post('/admin/Upload/edit',{'table_name':table_name,'table_field':table_field,'table_id':table_id,'id_value':id_value,'field_value':field_value},function(data){
                    console.log(data)
                    if(data.status == 1){
                        layer.msg(data.msg,{icon: 1});
                    }else{
                        layer.msg(data.msg,{icon: 2});
                    }
                },'json')
                layer.close(index);
            });
        }
    </script>
</block>